package cn.shuangliang.contract.web;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;

/**
 * @author oldliu
 * @since 1.0
 * 使用之前的功能。。。
 * 多个值。。。
 * jsp
 */
@Controller
@RequestMapping("/demo")
public class HelloController {

    @RequestMapping("/sayhi")
    public ModelAndView sayhello(){
        ModelAndView mv=new ModelAndView();
        mv.addObject("msg","凯旋，你好");
        mv.setViewName("/hello.jsp");//视图地址
        return mv;
    }
    @RequestMapping("/login")
    //请求的参数和handler中的参数名一致，自动绑定，自动做类型转换
    public String login(String userName, String userPass, HttpServletRequest request){
        //request.getParameter()
        request.setAttribute("tip","登录的信息是"+userName+","+userPass);
        return "/loginok.jsp";//表示视图的地址
    }

    @RequestMapping("/login2")
    //请求的参数和handler中的参数名不一致，@RequestParam解决
    public String login2(@RequestParam(name = "userName",required = true,defaultValue = "laoliu") String name,@RequestParam(name = "userPass",defaultValue = "123") String pass, HttpServletRequest request){
        //request.getParameter()
        request.setAttribute("tip","登录的信息是"+name+","+pass);
        return "/loginok.jsp";//表示视图的地址
    }
}
